<?php
ob_start();
session_start();

define( 'APP_PATH', 'application/');
define( 'PUBLIC_PATH', 'public/');

function __autoload( $class_name ) {
    $path =  APP_PATH . str_replace('_', '/', strtolower( $class_name )) . '.php';
    
    if(file_exists($path) ){
        @include_once ( $path );
        return true;
    }else{
        return false;
    }
}
class System_Twframework {
    private $_session_manager;
    private $_acl;
    private $_auth;
    private $_rooter;
    private $_database;
    private $_controller;
    
    function __construct(){
        $this->_session_manager = new System_App_Extends_Session_Manager();
        $this->_database = new System_App_Database();
        $this->_acl = new System_App_Acl();
        $this->_auth = new System_App_Auth();
        $this->_rooter = new System_App_Rooter();        
        $this->_controller = $this->_getController();
    }
    
    public function dispatch(){
        return $this->_controller->dispatch();
    }
    
    private function _getController(){
        $controllerName = $this->_rooter->getControllerName();
        if( class_exists( $controllerName, true ) ) {
            return new $controllerName();
        }else{
            System_App_Erreur::page404();
        }
    }
}

?>
